package com.muqi.app.qlearn.mine;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.muqi.app.qlearn.student.BaseFragmentActivity;
import com.muqi.app.qlearn.student.R;

public class MineFeedBackActivity extends BaseFragmentActivity implements
		OnClickListener {

	private EditText mFeedBackContent;
	private TextView mFeedBackNum;
	private Button mFeedBackCommit;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mine_feedback);
	}

	@Override
	protected void onInit() {
		mFeedBackContent = (EditText) findViewById(R.id.feedback_content);
		mFeedBackNum = (TextView) findViewById(R.id.feedback_num);
		mFeedBackCommit = (Button) findViewById(R.id.feedback_commit);
	}

	@Override
	protected void onData() {
		mFeedBackContent.clearFocus();
		final String string = mFeedBackContent.getHint().toString().trim();
		mFeedBackContent.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View arg0, boolean hasFocus) {
				if (hasFocus&&mFeedBackContent.getText().toString().trim().length()!=0) {
					mFeedBackContent.setHint("");
				} else {
					mFeedBackContent.setHint(string);
				}
			}
		});

		mFeedBackCommit.setOnClickListener(this);
		final int num = 500;// 限制的最大字数
		mFeedBackContent.addTextChangedListener(new TextWatcher() {
			private CharSequence temp;
			
			@Override
			public void afterTextChanged(Editable s) {
//				int currentNum = getWordCount(mFeedBackContent.getText()
//						.toString());
				int currentNum = mFeedBackContent.getText()
						.toString().length();
				int number = num - currentNum;
				mFeedBackNum.setText(String.valueOf(number));

			}
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {

			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {

			}
			

		});

	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.feedback_commit:
			if (mFeedBackContent.getText().toString().equals("")) {
				Toast.makeText(getApplicationContext(), "请填写您的意见后提交！", 0)
						.show();
			} else {

			}
			break;
		default:
			break;
		}

	}

}
